var scrollTop = 0;

function center(obj, replace) {
    $("document,body").css("overflow", "hidden");
    if (true !== replace) {
        scrollTop = $(document).scrollTop();
    }
    var clientHeight = $(window).height(),
        clientWidth = $(window).width(),
        objHeight = $(obj).height(),
        objWidth = $(obj).width(),
        PosTop = (clientHeight - objHeight) / 2,
        PosLeft = (clientWidth - objWidth) / 2;
    $(obj).css({
        "top": PosTop + "px",
        "left": PosLeft + "px",
        "display": "block",
        "position": "fixed",
        "z-index": 888
    });
    $("#mask").show();
    $(document.body).css({　　
        "overflow-y": "hidden",
        　　'position': 'fixed',
        　　'top': scrollTop * -1,
        　　'left': 0
    });
}
//隐藏弹窗

function Hide(obj, replace) {
    $("#mask").hide(); //隐藏遮罩层
    //        $("body").css("overflow","auto");
    $(obj).hide();
    if (replace === true) {
        return;
    }
    $(document.body).css({　　
        "overflow-y": "auto",
        　　'position': 'static',
        　　'top': 'auto'
    });
    $(document.body).scrollTop(scrollTop);
}
//tooltip 提示
function tooltip(text) {
    $(".tooltip").html(text);
    $(".tooltip").fadeIn(400);
    center(".tooltip");
    setTimeout(function () {
        $(".tooltip").fadeOut(400);
        Hide(".tooltip");
    }, 2000)
}
var mySwiper, mySwiper2;
var Api3 = 'https://' + document.domain + '/public/index.php';
window.onload = function () {
    var wwh = 900
        //$(".slide1").width()
    $(".img1").width(wwh);
    $(".img2").width(wwh);
    var wh = wwh * 2;
    $(".a_d21").width(wh);
    $(".a_d22").width(wh);
    var bo = 0;
    var bo1 = -wh / 2;
    setInterval(function () {
        if (bo < wh / 2) {
            bo = bo + 3;
            $(".a_d21").css({
                "left": -bo
            })
        } else {
            bo = 0;
            $(".a_d21").css({
                "left": -bo
            })
        }
        if (bo1 < 0) {
            bo1 = bo1 + 5;
            $(".a_d22").css({
                "left": bo1
            })
        } else {
            bo1 = -wh / 2;
            $(".a_d22").css({
                "left": bo1
            })
        }
    }, 30)

    mySwiper = new Swiper('.swiper-container', {
        autoplay: 5000, //可选选项，自动滑动
        loop: true,
        pagination: '.swiper-pagination',
        onInit: function (swiper) { //Swiper2.x的初始化是onFirstInit
            swiperAnimateCache(swiper); //隐藏动画元素 
            swiperAnimate(swiper); //初始化完成开始动画
        },
        onSlideChangeEnd: function (swiper) {
            swiperAnimate(swiper); //每个slide切换结束时也运行当前slide动画
            var idx = swiper.realIndex;
            console.log(idx)
            all_ani(idx);
        }
    })

    mySwiper2 = new Swiper('.swiper-container2', {
        autoplay: 5000, //可选选项，自动滑动
        loop: true,
        speed: 100,
        autoHeight: true, //高度随内容变化
        paginationClickable: true,
        onSlideChangeEnd: function (swiper) {
            console.log(swiper.realIndex) //切换结束时，告诉我现在是第几个slide
            $(".bullet").removeClass('bullet_active');
            $(".bullet").eq(swiper.realIndex).addClass('bullet_active');
        }
    })
    zw()
    odata(); //数据获取
    slide2_ani1();
}

function all_ani(index) {
    console.log(index)
    switch (index) {
    case 0:
        slide2_stop()
        break;
    case 1:
        slide2_ani()
        break;
    case 2:
        slide2_stop()
        break;
    case 3:
        slide2_stop()
        break;
    default:
        break;
    }
}
var time2, time21, time3, time4, time42;

function slide2_stop() {
    $(".shan_gao").stop().css({
        "bottom": "-0.50rem"
    });
    $(".shan_di").stop().css({
        "bottom": "-1rem"
    })
    $(".fadada_div").stop().css({
        "height": "0px",
        "margin-top": "1.57rem"
    });
    $(".fadada_text").stop().css({
        "top": "-0.67rem"
    });
    var rot = 0;
    var _scale = 1.5;
    $(".yuan_biao").stop().css({
        "transform": "rotate(" + rot + "deg)",
        "-moz-transform": "rotate(" + rot + "deg)",
        "-webkit-transform": "rotate(" + rot + "deg)",
        "-o-transform": "rotate(" + rot + "deg)",
        "-ms-transform": "rotate(" + rot + "deg)"
    })
    $(".yuan_div").stop().css({
        "transform": "scale(" + _scale + ")",
        "-moz-transform": "scale(" + _scale + ")",
        "-webkit-transform": "scale(" + _scale + ")",
        "-ms-transform": "scale(" + _scale + ")",
        "-o-transform": "scale(" + _scale + ")"
    });
}

function slide2_ani1() {
    var rot = 0;
    time21 = setInterval(function () {
        if (rot < 360) {
            rot = rot + 0.5;
            $(".yuan_biao").css({
                "transform": "rotate(" + rot + "deg)",
                "-moz-transform": "rotate(" + rot + "deg)",
                "-webkit-transform": "rotate(" + rot + "deg)",
                "-o-transform": "rotate(" + rot + "deg)",
                "-ms-transform": "rotate(" + rot + "deg)"
            })
        } else {
            rot = 0;
            $(".yuan_biao").css({
                "transform": "rotate(" + rot + "deg)",
                "-moz-transform": "rotate(" + rot + "deg)",
                "-webkit-transform": "rotate(" + rot + "deg)",
                "-o-transform": "rotate(" + rot + "deg)",
                "-ms-transform": "rotate(" + rot + "deg)"
            })
        }
    }, 30)
}

function slide2_ani() {
    $(".shan_gao").stop().animate({
        "bottom": "0"
    }, 2000)
    $(".shan_di").stop().delay(600).animate({
        "bottom": "0"
    }, 2000)
    $(".fadada_div").stop().animate({
        "height": "1.35rem",
        "margin-top": "0.9rem"
    }, 1000)
    $(".fadada_text").stop().animate({
        "top": "0px"
    }, 1000)
    var _scale = 1.5;
    clearInterval(time2);
    time2 = setInterval(function () {
        if (_scale > 1) {
            _scale = _scale - 0.04;
        } else {
            _scale = 1;
            clearInterval(time2);
        }
        $(".yuan_div").css({
            "transform": "scale(" + _scale + ")",
            "-moz-transform": "scale(" + _scale + ")",
            "-webkit-transform": "scale(" + _scale + ")",
            "-ms-transform": "scale(" + _scale + ")",
            "-o-transform": "scale(" + _scale + ")"
        });
    }, 30)
}

$(".xx").bind('click', function () {
    $(".sus").fadeOut(500);
    $(".zhanwei").animate({
        "height": '0'
    }, 200)
})

function odata() {
    //三个数据获取
    $.ajax({
        url: Api3 + '/api/home/count',
        type: "GET",
        async: true,
        dataType: "json",
        success: function (data) {
            if (data.status == 0) {
                console.log(data)

                $(".total span").html(data.data.total_money);
                $(".over_time").html("数据截止至：" + data.data.over_time);
                $(".join_inn span").html(data.data.registered_member);
                $(".return_inn span").html(data.data.income_gains)

                //数字跳动
                $('.counter').countUp({
                    time: 1500
                });
            }
        },
        error: function () {
            tooltip('暂无网络，请稍后再试');
        }
    });
}

function zw() {
    var he = $(".sus").height();
    $(".zhanwei").height(he);
}




$(".dload").on('click',function(){
	if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) { //判断ios
            window.location.href = "https://itunes.apple.com/cn/app/sha-xiao-seng-li-cai-ke-kao/id1095051707?mt=8"; //跳转到App store
    } else if (/(Android)/i.test(navigator.userAgent)) { //判断Android
       
            window.location.href = "https://file.shaxiaoseng.com/SXSFinanceAndroid.apk";
    }
})
    